<template>
  <div>
    <div>
      <page-title title="待评审订单/处理" home-path="/center/home"></page-title>
    </div>
    <div class="pageMain">
      <div class="pageMain-title">
        <span>技术评审</span>
      </div>
      <div class="pageMain-body">
        <div class="container">
          <div class="left-half">
            <order-detail :form-data="formData" :disabled="orderDetails.outsourcingStatus" @reloadOrder="getTableData"></order-detail>
          </div>
          <div class="vertical-line"></div>
          <div class="right-half">
            <div class="majorCategories">
              <h3>技术评审人员意见</h3>
              <el-table :data="tableData" border>
                <el-table-column
                  label="评审部门"
                  prop="department"
                  width="200"
                ></el-table-column>
                <el-table-column
                  label="评审人"
                  prop="assessor"
                  width="200"
                ></el-table-column>
                <el-table-column
                  label="评审意见"
                  prop="comment"
                ></el-table-column>
              </el-table>
              <table class="uTable" style="margin-top: 10px">
                <tbody>
                  <tr>
                    <td style="width: 180px"><span>是否引起成本变化</span></td>
                    <td>
                      {{ orderDetails.isCostByChange == null ? "" : orderDetails.isCostByChange == 0 ? "否" : "是" }}
                    </td>
                  </tr>
                  <tr>
                    <td><span>首试制</span></td>
                    <td>{{ orderDetails.isMake == null ? "" : orderDetails.isMake == 0 ? "否" : "是" }}</td>
                  </tr>
                  <tr>
                    <td><span>风险评估等级</span></td>
                    <td>
                      {{ orderDetails.assess == null ? "" : orderDetails.assess == 0
                      ? "高"
                      : orderDetails.assess == 1
                      ? "中"
                      : "低"
                      }}
                    </td>
                  </tr>
                  <tr>
                    <td><span>外委情况</span></td>
                    <td>{{ orderDetails.outsourcingStatus == null ? "" : orderDetails.outsourcingStatus == 0 ? "无需外委" : "需要外委"  }}</td>
                  </tr>
                </tbody>
              </table>
              <div>
                <span>成本预测：</span>
                <el-button type="text" size="medium">测算详情</el-button>
              </div>
              <!-- 评审结论 -->
              <div>
                <div>
                  <span>评审结论：</span>
                  <span>
                    {{ orderDetails.receivingState ? orderDetails.receivingState == 0 ? "不接单" : orderDetails.receivingState == 1 ? "接单" : orderDetails.receivingState == 2 ? "带条件生产" : "" : "" }}
                  </span>
                </div>
                <div v-if="orderDetails.receivingState && orderDetails.receivingState==2">
                  <span>评审备注：</span>
                  <span>{{ orderDetails.receivingRemark }}</span>
                </div>
              </div>
            </div>
            <div class="majorCategories">
              <h3>主任综合意见</h3>
              <el-form ref="zhurenRef" :model="formmatter" :rules="rules" label-width="240px">
                <el-form-item
                  label="总工办/技术中心主任/副主任意见"
                  prop="isConsent"
                >
                  <el-radio-group v-model="formmatter.isConsent">
                    <el-radio :label="1">同意</el-radio>
                    <el-radio :label="0">不同意</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item  prop="remark" label="备注">
                  <el-input
                    v-model="formmatter.remark"
                    :autosize="{ minRows: 2, maxRows: 4 }"
                    placeholder="请输入评审意见"
                    type="textarea"
                  ></el-input>
                </el-form-item>
              </el-form>
            </div>
            <div style="margin-left: 30%; margin-top: 10%">
              <el-button type="warning" size="mini" @click="returnBack">退回</el-button>
              <el-button type="success" size="mini" @click="jumpStandard">提交</el-button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import OrderDetail from "@/components/OrderDetail.vue";
import PageTitle from "@/components/PageTitle.vue";
import {
  getReviewerOpinion,
  rejectData,
  submitData,
  getReviewedLeftList
} from "@/lib/Api.js";
import { post } from "@/lib/Util.js";
export default {
  components: { OrderDetail, PageTitle },
  data() {
    return {
      formData: {},
      formmatter: {},
      orderDetails: {},
      rules: {
        isConsent: [{ required: true, message: "请选择", trigger: "change" }],
        remark: [{ required: true, message: "请填写意见", trigger: "blur" }]
      },
      tableData: []
    };
  },
  computed: {
    // 通过 Vuex getter 获取共享参数
    sharedId() {
      return this.$store.getters.getSharedId;
    }
  },
  mounted() {
    this.getReviewersOpinion();
    this.getTableData();
  },
  methods: {
    //获取左侧表格数据
    getTableData() {
      let data = {
        contractInfoId: this.sharedId
      };
      post(getReviewedLeftList, data).then(res => {
        if (res.code == 200) {
          this.formData = res.data;
        }
      });
    },
    jumpStandard() {
      this.$refs["zhurenRef"].validate(valid => {
        if (valid) {
          let data = {
            id: this.sharedId,
            isConsent: this.formmatter.isConsent,
            remark: this.formmatter.remark
          };
          post(submitData, data).then(res => {
            if (res.code == 200) {
              this.$message.success("提交成功！");
              this.$router.push({
                path: "/center/toBeReviewed"
              });
            } else {
              this.$notify({
                title: "提示",
                message: res.message
              });
            }
          });
        } else {
          return false;
        }
      });
    },
    //退回数据
    returnBack() {
      this.$confirm("是否确定要退回?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let data = {
            id: this.sharedId,
            isConsent: this.formmatter.isConsent,
            remark: this.formmatter.remark
          };
          post(rejectData, data).then(res => {
            if (res.code == 200) {
              this.$message.success("退回成功！");
              this.$router.push({
                path: "/center/toBeReviewed"
              });
            } else {
              this.$notify({
                title: "提示",
                message: res.message
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    //获取评审人员意见
    getReviewersOpinion() {
      let data = {
        id: this.sharedId
      };
      post(getReviewerOpinion, data).then(res => {
        if (res.code == 200) {
          this.tableData = res.data.reviewInfoDtoList;
          this.orderDetails = res.data;
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.container {
  display: flex;
  align-items: stretch;
  height: 100%;
}

.left-half,
.right-half {
  flex: 1;
  padding: 10px;
  width: 50%;
  margin: 0px 30px;
}
.vertical-line {
  width: 2px;
  height: 100%;
  background-color: #ccc;
  margin-left: 0 10px;
}
.majorCategories {
  margin-bottom: 30px;
  div {
    margin-top: 10px;
  }
}
/deep/ input[aria-hidden="true"] {
  display: none !important;
}

/deep/.el-radio:focus:not(.is-focus):not(:active):not(.is-disabled)
  .el-radio__inner {
  box-shadow: none !important;
}
</style>
